package com.mcjtf.prefix.listener;

import com.mcjtf.prefix.PrefixManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class PlayerListener implements Listener {
    private final PrefixManager plugin;

    public PlayerListener() {
        this.plugin = PrefixManager.getInstance();
    }

    @EventHandler()
    public void onPlayerJoinEvent(PlayerJoinEvent event) {
        plugin.getConfigService().loadPlayer(event.getPlayer());
        plugin.temp.remove(event.getPlayer().getName());
    }

    @EventHandler()
    public void onPlayerQuitEvent(PlayerQuitEvent event) {
        plugin.getConfigService().savePlayer(event.getPlayer().getName());
        plugin.getConfigService().dataCache.remove(event.getPlayer().getName());
    }
}
